package com.iias.communication.domain;


import com.iias.communication.business.BusinessSerializable;
import com.iias.communication.packet.PacketBody;

import java.lang.reflect.Method;

public class InstructionInfo {

    private Integer msgId;
    /**
     * 指令与业务实体关系
     */
    private BusinessSerializable businessSerializable;
    /**
     * 指令对应的处理方法
     */
    private Method method;

    /**
     * 对应的解码 编码方式
     */
    private String decodeFlag;


    private String remake;
    /**
     * 包体
     */
    private Class<? extends PacketBody> packBody;

    public InstructionInfo(Integer msgId, BusinessSerializable businessSerializable,
                           Method method, String decodeFlag) {
        this.msgId = msgId;
        this.businessSerializable = businessSerializable;
        this.method = method;
        this.decodeFlag = decodeFlag;
    }

    public InstructionInfo(Integer msgId, BusinessSerializable businessSerializable,
                           Method method, String decodeFlag, String remake,Class<? extends PacketBody> packetBody) {
        this.msgId = msgId;
        this.businessSerializable = businessSerializable;
        this.method = method;
        this.decodeFlag = decodeFlag;
        this.remake = remake;
        this.packBody = packetBody;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Integer && msgId.equals(obj))return true;

        if (obj instanceof BusinessSerializable && obj.getClass().getTypeName().equals(businessSerializable.getClass().getTypeName()))return true;

        if (obj instanceof PacketBody && obj.getClass().equals(packBody))return true;

        return super.equals(obj);
    }

    public Class<? extends PacketBody> getPackBody() {
        return packBody;
    }

    public void setPackBody(Class<? extends PacketBody> packBody) {
        this.packBody = packBody;
    }

    public String getRemake() {
        return remake;
    }

    public void setRemake(String remake) {
        this.remake = remake;
    }

    public Integer getMsgId() {
        return msgId;
    }

    public void setMsgId(Integer msgId) {
        this.msgId = msgId;
    }

    public BusinessSerializable getBusinessSerializable() {
        return businessSerializable;
    }

    public void setBusinessSerializable(BusinessSerializable businessSerializable) {
        this.businessSerializable = businessSerializable;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public String getDecodeFlag() {
        return decodeFlag;
    }

    public void setDecodeFlag(String decodeFlag) {
        this.decodeFlag = decodeFlag;
    }
}
